/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import model.Album;
import model.Artist;
import model.MusicGroup;

public class ArtistOrGroupCellRenderer extends DefaultTableCellRenderer {

    private Object artistStr;

    @Override
    public Component getTableCellRendererComponent(
            JTable table, Object value, boolean isSelected,
            boolean hasFocus, int row, int column) {
        if (value instanceof Album) {
            Album album = (Album) value;
            //pat3group: sky - Γράφω όνομα Καλλιτέχνη
            if (album.getArtistId() instanceof Artist) {
                Artist a = album.getArtistId();
                //pat3group: sky - Συνθέτω το ονοματεπώνυμο - ψευδώνυμο καλλιτέχνη
                String str = "";
                try {
                    str = (a.getArtistArtname().length() == 0) ? "" : ", (" + a.getArtistArtname() + ")";
                } catch (Exception e) {
                    System.out.println("Artist Artname null");
                }
                try {
                    artistStr = a.getArtistLname() + " " + a.getArtistFname() + str;
                } catch (Exception e) {
                    System.out.println("artist string error");
                }
            }
            //pat3group: sky - Γράφω όνομα Γκρουπ
            if (album.getAlbumMusicGroupId() instanceof MusicGroup) {
                artistStr = album.getAlbumMusicGroupId().getMusicGroupName();
            }
        }
        return super.getTableCellRendererComponent(table, artistStr, isSelected, hasFocus, row, column);
    }
}
